"use strict";
cc._RF.push(module, '72d61Yz231LY4HpNvsxGQdP', 'GradientColor');
// eazax-ccc/components/renderers/GradientColor.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, requireComponent = _a.requireComponent, disallowMultiple = _a.disallowMultiple, executeInEditMode = _a.executeInEditMode;
/**
 * 渐变颜色，支持 Sprite（SIMPLE 和 FILLED）和 Label，注意这会覆盖默认的节点颜色设置
 * @see GradientColor.ts https://gitee.com/ifaswind/eazax-ccc/blob/master/components/renderers/GradientColor.ts
 */
var GradientColor = /** @class */ (function (_super) {
    __extends(GradientColor, _super);
    function GradientColor() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this._colors = [cc.Color.RED, cc.Color.BLUE, cc.Color.RED, cc.Color.BLUE];
        return _this;
    }
    Object.defineProperty(GradientColor.prototype, "colors", {
        get: function () { return this._colors; },
        set: function (colors) {
            if (colors.length > 4) {
                colors.length = 4;
            }
            this._colors = colors;
            this.markForRender();
        },
        enumerable: false,
        configurable: true
    });
    GradientColor.prototype.onEnable = function () {
        this.replaceFunction();
    };
    GradientColor.prototype.onDisable = function () {
        this.restoreFunction();
    };
    GradientColor.prototype.resetInEditor = function () {
        this.markForRender();
    };
    /**
     * 替换颜色填充函数
     */
    GradientColor.prototype.replaceFunction = function () {
        var _this = this;
        // 获取渲染组件
        var renderComponent = this.getComponent(cc.RenderComponent);
        if (!renderComponent)
            return;
        // 获取装配器
        var assembler = renderComponent._assembler;
        if (!(assembler instanceof cc.Assembler2D))
            return;
        // 替换颜色填充函数
        assembler.updateColor = function () {
            // 获取颜色数据缓存
            var uintVDatas = assembler._renderData.uintVDatas[0];
            if (!uintVDatas)
                return;
            // 顶点数据
            var floatsPerVert = assembler.floatsPerVert; // 每个顶点的数据数量
            var colorOffset = assembler.colorOffset; // 颜色偏移
            var nodeColor = _this.node.color; // 节点颜色
            var offset = 0;
            for (var i = colorOffset, l = uintVDatas.length; i < l; i += floatsPerVert) {
                uintVDatas[i] = (_this.colors[offset++] || nodeColor)._val;
            }
        };
        // 标记
        this.markForRender();
    };
    /**
     * 还原颜色填充函数
     */
    GradientColor.prototype.restoreFunction = function () {
        // 获取渲染组件
        var renderComponent = this.getComponent(cc.RenderComponent);
        if (!renderComponent)
            return;
        // 获取装配器
        var assembler = renderComponent._assembler;
        if (!(assembler instanceof cc.Assembler2D))
            return;
        // 恢复颜色填充函数
        assembler.updateColor = cc.Assembler2D.prototype.updateColor;
        // 标记
        this.markForRender();
    };
    /**
     * 标记
     */
    GradientColor.prototype.markForRender = function () {
        this.node._renderFlag |= cc.RenderFlow.FLAG_COLOR;
    };
    __decorate([
        property
    ], GradientColor.prototype, "_colors", void 0);
    __decorate([
        property({ type: [cc.Color], tooltip: CC_DEV && '支持最多 4 种颜色（左下、右下、左上、右上）' })
    ], GradientColor.prototype, "colors", null);
    GradientColor = __decorate([
        ccclass,
        requireComponent(cc.RenderComponent),
        disallowMultiple,
        executeInEditMode
    ], GradientColor);
    return GradientColor;
}(cc.Component));
exports.default = GradientColor;

cc._RF.pop();